package hongcaosp.app.android.user.settings.wallet.presenter;

import java.util.List;

import hongcaosp.app.android.common.IListView;
import hongcaosp.app.android.contact.ListPresenter;
import hongcaosp.app.android.login.UserToken;
import hongcaosp.app.android.modle.DataCallBack;
import hongcaosp.app.android.modle.bean.Income;
import hongcaosp.app.android.modle.bean.Pagebean;
import hongcaosp.app.android.modle.impl.UserWalletModelImpl;

public class IncomePresenter extends ListPresenter {
    private IListView<Income> listView;
    private UserWalletModelImpl userWalletModel;

    private int number;
    private int total;
    private int type;

    public IncomePresenter(IListView<Income> listView,int type) {
        this.listView = listView;
        userWalletModel = new UserWalletModelImpl();
        this.type = type;
    }

    public void fresh() {
        number = 1;
        userWalletModel.rechargeRecord(UserToken.getDefault().getToken(), type,number, 20,
                new DataCallBack<Pagebean<Income>>() {
                    @Override
                    public void onGetData(Pagebean<Income> data) {
                        super.onGetData(data);
                        boolean loadMore = false;
                        total = data.getList() == null ? 0 : data.getList().size();
                        if (data.getTotal() > total) {
                            loadMore = true;
                        }
                        List<Income> videos = data.getList();
//                List<Message> videoList = new ArrayList<>();
//                videoList.addAll(videos);
                        listView.freshList(videos, loadMore);
                    }

                    @Override
                    public void onFail(int code, String errorMessage) {
                        super.onFail(code, errorMessage);
                        listView.freshList(null, false);
                    }
                });
    }

    public void loadMoreData() {
        number++;
        userWalletModel.rechargeRecord(UserToken.getDefault().getToken(), 3, number, 20,
                new DataCallBack<Pagebean<Income>>() {
                    @Override
                    public void onGetData(Pagebean<Income> data) {
                        super.onGetData(data);
                        boolean loadMore = false;
                        total += data.getList() == null ? 0 : data.getList().size();
                        if (data.getTotal() > total) {
                            loadMore = true;
                        }
                        List<Income> videos = data.getList();
//                List<Message> videoList = new ArrayList<>();
//                videoList.addAll(videos);
                        listView.addList(videos, loadMore);
                    }

                    @Override
                    public void onFail(int code, String errorMessage) {
                        super.onFail(code, errorMessage);
                        listView.addList(null, false);
                    }
                });
    }

    @Override
    public void freshData() {
        fresh();
    }

    @Override
    public void loadMore() {
        loadMoreData();
    }
}
